package router

import (
	"github.com/gin-gonic/gin"
	"lib/middleware"
	"runtime/debug"
)

func Routers() *gin.Engine {
	var router = gin.Default()
	router.Use(middleware.Cors())
	//router.Use(gzip.Gzip(gzip.DefaultCompression))
	//router.Use(Recovery())
	//store := cookie.NewStore([]byte("secret"))
	//router.Use(sessions.Sessions("mysession", store))

	addUserRouters(router.Group("/api/user/v2"))
	addIndexRouters(router.Group("/api/index/v2"))

	return router
}

func Recovery() func(c *gin.Context) {
	return func(c *gin.Context) {
		defer func() {
			if err := recover(); err != nil {
				c.AbortWithStatusJSON(500, map[string]interface{}{})
				debug.PrintStack()
			}
		}()
		c.Next() // 调用下一个处理
	}
}
